package com.kfm.springboot.autoconfig.config;

import com.kfm.springboot.autoconfig.custom.MyDataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringConfig {

    @Bean
    // @Conditional注解的作用是：当 MyClassCondition 类中的 matches 方法返回 true 时，才会创建MyDataSource对象
//    @Conditional(MyClassCondition.class)
//    @ConditionalOnBean(name = "datasource")
//    @ConditionalOnMissingBean(name = "datasource")
//    @ConditionalOnClass(name = "com.mysql.cj.jdbc.Driver")
    @ConditionalOnProperty(name = "mydatasource.enable", havingValue = "true")
    public MyDataSource myDataSource(){
        return new MyDataSource();
    }
}
